#include "bits/stdc++.h"
using namespace std;
void selectSort(vector<int> &vec_a, int i) // i表示当前位置，n表示数组的长度
{
    // 选择排序的递归
    if (i == vec_a.size())
    {
        return;
    }
    int k = i;
    for (int j = i + 1; j < vec_a.size(); j++)
    {
        if (vec_a[j] > vec_a[k])
        {
            k = j;
        }
    }
    int temp = vec_a[k];
    vec_a[k] = vec_a[i];
    vec_a[i] = temp;
    selectSort(vec_a, i + 1); // 递归 下一组
}


int main()
{

    vector<int> ivec;
    for (auto i = 0; i < 5; i++)
    {
        int temp = i * 2;
        ivec.push_back(temp);
    }

    for (auto c : ivec)
    {
        cout << c;
        cout << " ";
    }
    // 选择排序
    int k, t;
    for (int i = 0; i < ivec.size(); i++)
    {
        k = i;
        for (int j = i + 1; j < ivec.size(); j++)
        {
            if (ivec[k] < ivec[j])
            {
                k = j;
            }
        }
        t = ivec[k];
        ivec[k] = ivec[i];
        ivec[i] = t;
    }
    cout << "排序后的值为："
         << "\n";
    for (auto c : ivec)
    {
        cout << c;
        cout << " ";
    }
    cout << "\n用递归之后的排序可能";
    cout << "\n";
    // 运用递归的选择排序
    vector<int> ivec2 = ivec;
    selectSort(ivec2, 0);
    for (auto c : ivec2)
    {
        cout << c;
        cout << " ";
    }
    cout << "\n用stl算法函数sort排序后的结果:" << endl;
    sort(ivec2.begin(), ivec2.end());
    for (auto c : ivec2)
    {
        cout << c;
        cout << " ";
    }

}